#include "ql_oe.h"
#include "../include/leds.hpp"
#include "../include/timer.hpp"
#include "../include/dial.hpp"
#include "../include/status_demon.hpp"
#include "../include/dtu.hpp"

statusDemon :: statusDemon()
	: chk_intval( [this]{ run();} , 5000 , true)
{
	std::shared_ptr< CSysVar > ptvar = GetOrCreateSysVar();
	if( ptvar ){
		long intval;
		ptvar->GetValue( "" , intval);

		chk_intval( intval );
	}
}

statusDemon :: ~statusDemon()
{
	chk_intval.Stop();
}

void run()
{
	led   lights;
	// 执行检查任务
	try{
		dial::sim_type radio_type = ec20dial :: check_radio();
		
		switch( radio_type ){
		case ec20dial :: _2G:
			lights.net_2g( true );
			break;
		case ec20dial::_3G:
			lights.net_3g( true );
			break;
		case ec20dial::_4G:
			lights.net_4g( true );
			break;
		default:
			light.net_off();
			break;
		}
		dtu * pdtu = GetOrCreateDTU();
		if( pdtu ){
			lights.socka( pdtu->IsSockConnect( 1 ) );
			lights.sockb( pdtu->IsSockConnect( 2 ) );
		}else{
			// TODO 添加错误处理内容
		}
	}catch( led::err_code e ){
	}catch( l
	// 准备下一次的
	chk_intval.Start(-1 , true );
}

